/**
 * @project name:crm
 */
package com.yunbo.crm.controller;

import com.yunbo.crm.base.BaseController;
import com.yunbo.crm.pojo.User;
import com.yunbo.crm.service.UserService;
import com.yunbo.crm.utils.LoginUserUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author : yun&bo
 * @CreateDate : ==>2021/1/19 16:19
 * @ClassName : ==>
 * @Description : ==>
 * @Version
 */
@Controller
public class IndexController extends BaseController {

    @Resource
    private UserService userService;

    /**
     * 系统登录⻚
     *
     * @return
     */
    @RequestMapping({"index","/",""})
    public String index() {
        return "index";
    }


    // 系统界⾯欢迎⻚
    @RequestMapping("welcome")
    public String welcome() {
        return "welcome";
    }

    /**
     * 后端管理主⻚⾯
     *
     * @return
     */
    @RequestMapping("main")
    public String main(HttpServletRequest servletRequest) {
        /**
         * 登入成功后查询当前登入用户信息
         */
        Integer userId = LoginUserUtil.releaseUserIdFromCookie(servletRequest);
        /**
         * 通过用户ID查询用户对象
         */
        User user = userService.selectByPrimaryKey(userId);

        servletRequest.setAttribute("user", user);
        return "main";
    }

}
